<include file="Common/works/header" />
<include file="Common/works/left_menu" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/waitMe.css" />
<!-- <form action="/apiworks/apiAdd.html" class="right" id="tab1" method="post"> -->

<div action="/apiworks/apiAdd.html" class="right" id="tab1" method="post">
	<div class="faservice_title">
		<a href="/apiworks/apiList" title="我的API">我的API</a>&nbsp;&gt;&nbsp;{$info.service_name}&nbsp;&gt;&nbsp;更新API</div>
	<div class="faservice">
		<div class="column">
			<div class="fielbt"><span class="fielbtbt">更新API</span	><span>{$info.create_time|date='Y-m-d H:i:s',###}</span></div>
		</div>
		<div class="column">
			<div class="fieldt">所属服务:<span>{$info.service_name}</span></div>
		</div>
		<div class="column">
			<div class="field">API名称:</div>
			<input name="api_name" id="api_name" opt-tip="请输入API名称" class="kt1 fl _api_name _blur_rz" value="{$info.api_name}" maxlength="20" placeholder="请填写中文名称，不超过10个字" />
			<div id="api_name_id" class="error hide">
				<i></i><span id="api_name_msg"></span>
			</div>
		</div>
		<div class="column">
			<div class="field">英文名称:</div>
			<input name="api_name_en" disabled="disabled" id="api_name_en" opt-tip="请输入API英文名称" class="kt1 fl _api_name_en _blur_rz" value="{$info.api_name_en}" autocomplete="on" maxlength="40" placeholder="请填写您API地址中的api_name" />
			<div id="api_name_en_id" class="error hide">
				<i></i><span id="api_name_en_msg"></span>
			</div>
			<div class="cls"></div>
		</div>
		<div class="column">
			<div class="fieldd">英文名称用于生成云途数据的API地址： https://api.37degree.com/open/{$info.service_name_en}/<span style=" color:#1080f2">api_name</span> 保存后不能修改</div>
		</div>
		<div class="cls"></div>
		<div class="column">
			<div class="field">API介绍:</div>
			<textarea name="api_introduction" opt-tip="请输入API介绍" id="api_introduction" class="textarea fl _api_introduction _blur_rz" placeholder="请填写API介绍" />{$info.api_introduction}</textarea>
			<div id="api_introduction_id" class="error hide" style="margin-top: 36px">
				<i></i><span id="api_introduction_msg"></span>
			</div>
		</div>
		<div class="column">
			<div class="fieldt fl">请求方式:</div>
			<div class="classification"> <input name="api_request_method" class="xz api_request_method" type="radio" value="0" <if condition="$info.api_request_method eq 0">checked="checked"</if>
				/> GET/POST
			</div>
			<div class="classification"> <input name="api_request_method" <if condition="$info.api_request_method eq 1">checked="checked"</if>
				class="xz api_request_method" type="radio" value="1"/> POST
			</div>
			<div class="classification"> <input name="api_request_method" <if condition="$info.api_request_method eq 2">checked="checked"</if>
				class="xz api_request_method" type="radio" value="2"/> GET
			</div>
			<div class="cls"></div>
		</div>
		<div class="column">
			<div class="fieldt fl">返回格式:</div>
			<div class="classification"> <input name="api_result_format" <if condition="strtolower($info['api_result_format']) eq 'json'">checked="checked"</if>
				class="xz _api_result_format" type="radio" value="json" checked="checked"/> JSON
			</div>
			<!--<div class="classification"> <input name="api_result_format" 
        <if condition="strtolower($info['api_result_format']) eq 'xml'">checked="checked"</if>
        class="xz _api_result_format" type="radio" value="xml"/>
        XML</div>-->
			<div class="cls"></div>
		</div>
		<div class="column">
			<div class="fieldt">授权方式: <span>HTTP Basic Authentication</span>
				<input type="hidden" value="HTTP Basic Authentication" class="_api_authorized_type" />
			</div>
		</div>
		<div class="column">
			<div class="fieldt fl">API地址 ： </div>
			<!-- <div class="slurl">106.4.46.151:80</div> -->
			<div class="slurl">http://{$info.service_host}/
				<span><input name="api_uri" id="api_uri" <if condition="$in_white_list neq 1">disabled="disabled"</if> class="kt7 _api_uri" autocomplete="on"  maxlength="50" value="{$info.api_uri}"/></span>
			</div>
			<div class="commentaryt">&nbsp;&nbsp;API完整的请求地址(不带参数)</div>
			<div class="cls"></div>
		</div>
		<div class="column" style="width:100%"> </div>
		<div class="column">
			<div class="fieldt">请求参数:</div>
		</div>
		<div class="column">
			<div class="table-top">
				<div class="tab" style=" width:12%">参数名</div>
				<div class="tab" style=" width:12%">类型</div>
				<div class="tab" style=" width:12%">是否必填</div>
				<div class="tab" style=" width:31%">示例默认值</div>
				<div class="tab" style=" width:31%">说明</div>
			</div>
			<!-- 循环 -->
			<div jput="users" jput-jsondata='[]'>
				<div class="_raw_request_param">
					<div class="table-foot fl _ul_li">
						<div class="tab" style=" width:12%">
							<input name="api_request_param" id="" value="{{json.req_name}}" onblur="javascript:checkValue(this);return false;" onfocus="javascript:rmError(this);return false;" class="kt5" autocomplete="on" maxlength="50" style="width:90%" />
						</div>
						<div class="tab" style=" width:12%">
							<div class="select">
								<div>
									<select class="kt5 _api_request_param" id="api_request_param_type" onchange="javascript:selectChange(this,'api_request_param',$(this).val());return false;">
										<option value="string" {{json.req_type1}}>string</option>
										<option value="number" {{json.req_type2}}>number</option>
										<option value="boolean" {{json.req_type3}}>boolean</option>
									</select>
									<input type="hidden" name="api_request_param" value="{{json.req_type}}" class="_api_request_param_type" />
								</div>
							</div>
							<!--选中项值-->
						</div>
						<div class="tab" style=" width:12%">
							<div class="select">
								<div>
									<select class="kt5" id="api_request_param_master" onchange="javascript:selectChange(this,'api_request_param',$(this).val());return false;">
										<option value="1" {{json.req_master1}}>是</option>
										<option value="0" {{json.req_master2}}>否</option>
									</select>
									<input type="hidden" name="api_request_param" value="{{json.req_master}}" class="_api_request_param_master" />
								</div>
							</div>
							<!--选中项值-->
						</div>
						<div class="tab" style=" width:31%">
							<input name="api_request_param" id="" value="{{json.req_default_value}}" class="kt5" autocomplete="on" maxlength="50" />
						</div>
						<div class="tab" style=" width:31%">
							<input name="api_request_param" id="" value="{{json.req_desc}}" class="kt5" autocomplete="on" />
						</div>
					</div>
					<div class="commentaryy">
						<a href="javascript:void(0)" class="_request_param_del">删除</a>
					</div>
				</div>
			</div>
			<!-- 循环 -->
		</div>
		<div class="cls"></div>
		<div class="column" style="height:50px; margin-top:16px">
			<a href="javascript:void(0)" id="save" class="cobed" title="继续添加">继续添加</a>
		</div>
		<div class="column">
			<div class="fieldt">返回字段:</div>
		</div>
		<div class="column">
			<div class="table-top">
				<div class="tab" style="width:33%">字段名</div>
				<div class="tab" style="width:33%">类型</div>
				<div class="tab" style="width:33%">说明</div>
			</div>

			<!-- 循环 -->
			<div jput="users1" jput-jsondata='[]'>
				<div class="_raw_return_param">
					<div class="table-foot fl">
						<div class="tab" style="width:33%">
							<input name="api_result_field" onblur="javascript:checkValue(this);return false;" onfocus="javascript:rmError(this);return false;" value="{{json.ret_name}}" class="kt5" autocomplete="on" maxlength="50" />
						</div>
						<div class="tab" style="width:33%">
							<div class="select" style="width:97%">
								<div style="width:100%">
									<select class="kt5" onchange="javascript:selectChange(this,'api_result_field',$(this).val());return false;" style="width:100%">
										<option value="string" {{json.ret_type1}}>string</option>
										<option value="number" {{json.ret_type2}}>number</option>
										<option value="boolean" {{json.ret_type3}}>boolean</option>
									</select>
									<input type="hidden" name="api_result_field" value="{{json.ret_type}}" class="_api_return_result_type" />
								</div>
							</div>
							<!--选中项值-->
						</div>
						<div class="tab" style="width:33%">
							<input name="api_result_field" id="" value="{{json.ret_desc}}" class="kt5" autocomplete="on" />
						</div>
					</div>
					<div class="commentaryy">
						<a href="javascript:void(0)" class="_return_param_del">删除</a>
					</div>
				</div>
			</div>
			<!-- 循环 -->

		</div>
		<div class="cls"></div>
		<div class="column" style="height:50px; margin-top:16px">
			<a href="javascript:void(0)" id="save1" class="cobed" title="继续添加">继续添加</a>
		</div>

		<div class="column">
			<div class="fieldt">返回示例(JSON/XML):</div>
		</div>
		<div class="column" style="width: 100%">
			<textarea name="api_result_sample" id="column" class="textarea1 _api_result_sample" autocomplete="on">{$info.api_result_sample}</textarea>
		</div>

		<div class="column">
			<div class="fieldt">错误码:</div>
		</div>
		<div class="column">
			<div class="table-top">
				<div class="tab" style="width:33%">错误码</div>
				<div class="tab" style="width:33%">错误信息</div>
				<div class="tab" style="width:33%">错误码返回说明</div>
			</div>

			<!-- 循环 -->
			<div jput="users2" jput-jsondata='[]'>
				<div class="_raw_error_param">
					<div class="table-foot fl">
						<div class="tab" style="width:33%">
							<input name="api_error_codes" id="name" value="{{json.error_code}}" class="kt5" autocomplete="on" maxlength="50" />
						</div>
						<div class="tab" style="width:33%">
							<input name="api_error_codes" id="" value="{{json.error_info}}" class="kt5" autocomplete="on" />
						</div>
						<div class="tab" style="width:33%">
							<input name="api_error_codes" id="" value="{{json.error_desc}}" class="kt5" autocomplete="on" />
						</div>
					</div>
					<div class="commentaryy">
						<a href="javascript:void(0)" class="_error_param_del">删除</a>
					</div>
				</div>
			</div>
			<!-- 循环 -->
		</div>
		<div class="cls"></div>
		<div class="column" style="height:50px; margin-top:16px">
			<a href="javascript:void(0)" id="save2" class="cobed" title="继续添加">继续添加</a>
		</div>
		<div class="column">
			<div class="fieldt fl">数据更新类型:</div>
			<div class="classification"> <input name="api_update_type" id="service_name" class="xz" type="radio" value="1" <if condition="$info.api_update_type eq 1">checked="checked"</if>
				/> 实时更新
			</div>
			<div class="classification"> <input name="api_update_type" id="service_name" class="xz" type="radio" value="2" <if condition="$info.api_update_type eq 2">checked="checked"</if>
				/> 静态数据
			</div>
			<div class="cls"></div>
		</div>
		<div class="column _chargeType">
			<div class="fieldt fl">收费类型:</div>
			<div class="classification"> <input name="api_is_charge" class="xz" type="radio" value="0" <if condition="$info.api_is_charge eq 0">checked="checked"</if>
				/> 免费
			</div>
			<div class="classification"> <input name="api_is_charge" class="xz" type="radio" value="1" <if condition="$info.api_is_charge eq 1">checked="checked"</if>
				/> 收费（设置资费规则，请联系support@37degree.com）
			</div>
			<div class="cls"></div>

			<?php if($info['api_is_charge']== 1){ ?>
			<div class="column _mainJudge">
				<div class="table-top">
					<div class="tab" style="width:20%">套餐周期</div>
					<div class="tab" style="width:20%">价格</div>
					<div class="tab" style="width:20%">调用次数</div>
					<div class="tab" style="width:20%">每次返回</div>
					<div class="tab" style="width:19%">并发次数</div>
				</div>

				<foreach name="info['api_charge_rules']" item="rules" key="ruleskey">
					<div class="_raw_error_param _addJudge">
						<div class="table-foot fl">

							<div class="tab" style="width:20%">
								<select class="kt5 _api_request_param" id="api_request_param_type">
									<option value="1个月" <if condition="$rules['package_date'] eq 31">selected="selected"</if>>1个月</option>
									<option value="3个月" <if condition="$rules['package_date'] eq 92">selected="selected"</if> >3个月</option>
									<option value="半年" <if condition="$rules['package_date'] eq 183">selected="selected"</if>>半年</option>
									<option value="一年" <if condition="$rules['package_date'] eq 365">selected="selected"</if>>一年</option>
								</select>
								<input type="hidden" name="api_date" value="{$rules['package_cycle']}" class="_api_request_param_type" />
							</div>

							<div class="tab" style="width:20%">
								<input name="" mandatory="on" value="{$rules.package_price}" class="kt5" autocomplete="off" maxlength="50" style="width:80%" />
								<span class="package-danwei">元</span>
							</div>

							<div class="tab" style="width:20%">
								<input name="" mandatory="on" value="{$rules.limit_num}" class="kt5" autocomplete="off" maxlength="50" style="width:80%" />
								<span class="package-danwei">次</span>
							</div>

							<div class="tab" style="width:20%">
								<input name="return_num" value="{$rules.return_num}" class="kt5" autocomplete="off" maxlength="50" style="width:80%" />
								<span class="package-danwei">条</span>
							</div>

							<div class="tab" style="width:19%">
								<input name="con_num" value="{$rules.con_num}" class="kt5" autocomplete="off" maxlength="50" style="width:70%" />
								<span class="package-danwei" style="width:20%">次/秒</span>
							</div>

							<div class="commentaryy "></div>

						</div>

						<input name="package_name" value="{$rules.package_name}" type="hidden" />
						<input name="package_date" value="{$rules.package_date}" type="hidden" />
					</div>
				</foreach>

			</div>
			<div class="cls"></div>
			<div class="column _mainJudge_2" style="height:50px; margin-top:16px;">
				<a href="javascript:void(0)" class="cobed _setMeal" title="继续添加">继续添加</a>
			</div>
			<?php }?>

		</div>

		<div class="column _mainJudge" style="display: none;">
			<div class="table-top">
				<div class="tab" style="width:20%">套餐周期</div>
				<div class="tab" style="width:20%">价格</div>
				<div class="tab" style="width:20%">调用次数</div>
				<div class="tab" style="width:20%">每次返回</div>
				<div class="tab" style="width:19%">并发次数</div>
			</div>

			<div class="_raw_error_param _addJudge">
				<div class="table-foot fl">
					<div class="tab" style="width:20%">
						<select class="kt5 _api_request_param" id="api_request_param_type">
							<option value="1个月">1个月</option>
							<option value="3个月">3个月</option>
							<option value="半年">半年</option>
							<option value="一年">一年</option>
						</select><input type="hidden" name="api_date" value="1个月" class="_api_request_param_type"></div>
					<div class="tab" style="width:20%"><input name="" mandatory="on" value="" class="kt5" autocomplete="off" maxlength="50" style="width:80%"><span class="package-danwei">元</span></div>
					<div class="tab" style="width:20%"><input name="" mandatory="on" value="" class="kt5" autocomplete="off" maxlength="50" style="width:80%"><span class="package-danwei">次</span></div>
					<div class="tab" style="width:20%"><input name="" value="" class="kt5" autocomplete="off" maxlength="50" style="width:80%"><span class="package-danwei">条</span></div>
					<div class="tab" style="width:19%"><input name="" value="" class="kt5" autocomplete="off" maxlength="50" style="width:70%"><span class="package-danwei" style="width:22%">次/秒</span></div>
				</div>
				<div class="commentaryy "></div>
			</div>

		</div>
		<div class="cls"></div>
		<div class="column _mainJudge_2" style="height:50px; margin-top:16px; display:none">
			<a href="javascript:void(0)" class="cobed _setMeal" title="继续添加">继续添加</a>
		</div>

		<div class="commentaryt">如果您已在其他平台发布该API，请填写其他平台的链接，帮助您更快通过审核，如果没有请勿填写。</div>
		<div class="column" style="width:100%">
			<input name="api_other_platform_sample" id="api_other_platform_sample" class="kt6 _api_other_platform_sample" autocomplete="on" maxlength="50" value="{$info.api_other_platform_sample}" />
		</div>
		<div class="column" style="margin-top:20px">
			<button type="button" data-authstatus="1" class="confirm _api_add_submit" id="register_api">提交审核</button>
			<div class="cls"></div>
		</div>
	</div>
	<!-- </form> -->
</div>
<input type="hidden" value="{$info.service_id}" class="_service_id" />
<input type="hidden" value="{$info.service_name_en}" class="_service_name_en" />
<input type="hidden" value="{$info.service_name}" class="_service_name" />
<input type="hidden" value="{$info.api_id}" class="_api_id" />
<input type="hidden" value="{$info.src_api_status}" class="_src_api_status" />

</body>
<script src="__PUBLIC__/home/js/jput-2.js"></script>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/home/js/serviceapi_common.js"></script>
<script type="text/javascript">
	$(function() {

		//组装请求参数数据
		request_param();
		//组装返回值参数
		return_param();
		//组装错误码参数
		error_param();
		//提交审核
		$("._api_add_submit").click(function() {
			var data = getApiData();
			data.api_charge_rules = getPackageData();
			data.src_api_status = $('._src_api_status').val();
			data.api_auth_status = 1;
			if(!data) {
				return;
			}
			var cur = $(this);
			// 按钮置为不可点击
			it_enable(cur, true);
			$('#register').attr("disabled", true);
			$('#register_api').text('');
			run_waitMe('register');

			function run_waitMe(register) {
				$('#register_api').waitMe({
					effect: 'ios',
					bg: 'rgba(16,128,242,0)',
					text: '提交中...',
					color: '#fff',
					padding: '10px',
					sizeW: '',
					sizeH: '',
					source: 'img.svg'
				});
			}
			console.log(data)
			
			
			function sortCircle(arr) {
				for(var i = 0; i < arr.length; i++) {
					for(var j = 0; j < arr.length - i - 1; j++) {
						if(arr[j] > arr[j + 1]) {
							var temp = arr[j];
							arr[j] = arr[j + 1];
							arr[j + 1] = temp;
						}
					}
				}
				return arr;
			}



			$.ajax({
				url: '/apiworks/apiStatusUpdate.html',
				type: 'POST',
				dataType: 'json',
				async: true,
				data: data,
				success: function(req) {
					it_enable(cur, false);
					$('#register').attr("disabled", false);
					$('#register_api').waitMe('hide');
					$('#register_api').text('提交审核');
					if(req.status == 200) {
						show_msg({
							msg: req.msg,
							type: 'ok',
							time: 1000
						});
						location.href = "/apiworks/apiList.html?service_id=" + data.service_id + "&api_type=1";
					} else {
						if(req.status == 1) {
							add_auth_error(req.data, req.msg);
						} else {
							show_msg({
								msg: req.msg,
								type: 'error'
							});
						}
					}
					return false;
				},
				error: function() {
					it_enable(cur, false);
					$('#register').attr("disabled", false);
					$('#register_api').waitMe('hide');
					$('#register_api').text('提交审核');
					show_msg({
						msg: '系统异常',
						type: 'error',
						time: 1000
					});
				}
			});

		});

		//临时保存
		$('._api_save').click(function() {
			var data = getApiData();
			data.api_auth_status = $(this).attr('data-authstatus');

			if(!data) {
				return;
			}
			var cur = $(this);
			// 按钮置为不可点击
			$('#register').text('');
			$('#register_api').attr("disabled", "true");
			run_waitMe('register');

			function run_waitMe(register) {
				$('#register').waitMe({
					effect: 'ios',
					bg: 'rgba(16,128,242,0)',
					text: '保存中...',
					color: '#fff',
					padding: '10px',
					sizeW: '',
					sizeH: '',
					source: 'img.svg'
				});
			}

			$.ajax({
				url: '/apiworks/apiEdit.html',
				type: 'POST',
				dataType: 'json',
				async: true,
				data: data,
				success: function(req) {
					$('#register_api').attr("disabled", false);
					$('#register').waitMe('hide');
					$('#register').text('保存');

					if(req.status == 200) {
						show_msg({
							msg: req.msg,
							type: 'ok',
							time: 1000
						});
					} else {
						if(req.status == 1) {
							add_auth_error(req.data, req.msg);
						} else {
							show_msg({
								msg: req.msg,
								type: 'error'
							});
						}
					}
					return false;
				},
				error: function() {
					$('#register_api').attr("disabled", false);
					$('#register').waitMe('hide');
					$('#register').text('保存');

					show_msg({
						msg: '系统异常',
						type: 'error',
						time: 1000
					});
				}
			});
		});

		$('#save').click(function() {
			//defining new user
			var user = Object();
			user['req_name'] = '';
			user['req_desc'] = '';
			user['req_default_value'] = '';
			user['req_type'] = 'string';
			user['req_master'] = '1';
			user['req_master1'] = 'selected';
			user['req_master2'] = 'id';
			user['req_type1'] = 'selected';
			user['req_type2'] = 'id';
			user['req_type3'] = 'id';
			jPut.users.append(user);
		});

		//on new user
		$('#save1').click(function() {
			//defining new user
			var user1 = Object();
			user1['ret_name'] = '';
			user1['ret_desc'] = '';
			user1['ret_type'] = 'string';
			user1['ret_type1'] = 'selected';
			user1['ret_type2'] = 'id';
			user1['ret_type3'] = 'id';
			user1['ret_desc'] = '';
			jPut.users1.append(user1);
		});

		//on new user
		$('#save2').click(function() {
			//defining new user
			var user2 = Object();
			user2['error_code'] = '';
			user2['error_info'] = '';
			user2["error_desc"] = '';
			jPut.users2.append(user2);
		});

	});

	function checkValue(obj) {
		var value = $(obj).val(); //.attr('value');
		if(value != '' && !checkEnName(value)) {
			$(obj).addClass('warning');
		}
	}

	function rmError(obj) {
		$(obj).removeClass('warning');
	}

	//把请求参数写入页面
	function request_param() {
		var jsondata = <?php echo json_encode($info['api_request_param']); ?>;
		if(jsondata == '' || jsondata == null) {

			var user = Object();
			user['req_name'] = '';
			user['req_desc'] = '';
			user['req_default_value'] = '';
			user['req_type'] = 'string';
			user['req_master'] = '1';
			user['req_master1'] = 'selected';
			user['req_master2'] = 'id';

			user['req_type1'] = 'selected';
			user['req_type2'] = 'id';
			user['req_type3'] = 'id';
			jPut.users.append(user);
			return;
		}

		var data = JSON.parse(jsondata);
		for(var a in data) {
			var user = Object();
			user['req_name'] = data[a].name;
			user['req_type'] = data[a].type;
			user['req_master'] = data[a].mast;
			user['req_desc'] = data[a].desc;
			user['req_default_value'] = data[a].default_value;

			user['req_master1'] = "id";
			user['req_master2'] = "id";
			if(data[a].mast == 1) {
				user['req_master1'] = "selected";
			} else {
				user['req_master2'] = "selected";
			}

			user['req_type1'] = "id";
			user['req_type2'] = "id";
			user['req_type3'] = "id";
			if(data[a].type == 'number') {
				user['req_type2'] = "selected";
			} else if(data[a].type == 'boolean') {
				user['req_type3'] = "selected";
			} else {
				user['req_type1'] = "selected";
			}

			jPut.users.append(user);
		}
	}

	//把请求返回参数写入页面
	function return_param() {
		var jsondata = <?php echo json_encode($info['api_result_field']); ?>;
		if(jsondata == '' || jsondata == null) {
			var user1 = Object();
			user1['ret_name'] = '';
			user1['ret_desc'] = '';
			user1['ret_type'] = 'string';

			user1['ret_type1'] = 'selected';
			user1['ret_type2'] = 'id';
			user1['ret_type3'] = 'id';
			jPut.users1.append(user1);
			return;
		}

		var data = JSON.parse(jsondata);
		for(var a in data) {
			var user1 = Object();
			user1['ret_name'] = data[a].name;
			user1['ret_type'] = data[a].type;
			user1['ret_desc'] = data[a].desc;

			user1['ret_type1'] = "id";
			user1['ret_type2'] = "id";
			user1['ret_type3'] = "id";
			if(data[a].type == 'number') {
				user1['ret_type2'] = "selected";
			} else if(data[a].type == 'boolean') {
				user1['ret_type3'] = "selected";
			} else {
				user1['ret_type1'] = "selected";
			}

			jPut.users1.append(user1);
		}
	}

	//把错误码写入页面
	function error_param() {

		var jsondata = <?php echo json_encode($info['api_error_codes']); ?>;
		if(jsondata == '' || jsondata == null) {
			var user2 = Object();
			user2['error_code'] = '';
			user2['error_info'] = '';
			user2['error_desc'] = '';
			jPut.users2.append(user2);
			return;
		}

		var data = JSON.parse(jsondata);
		for(var a in data) {
			var user2 = Object();
			user2['error_code'] = data[a].code;
			user2['error_info'] = data[a].info;
			user2['error_desc'] = data[a].desc;
			jPut.users2.append(user2);
		}
	}

	//把错误码写入页面
	// function rules_param(){

	//   var jsondata = <?php echo json_encode($info['api_charge_rules']); ?>;
	//   if(jsondata=='' || jsondata==null){
	//     var user_rules=Object();
	//       user_rules['error_code']='';
	//       user_rules['error_info']='';
	//       user_rules['error_desc']='';
	//     jPut.users_ruels.append(user_rules);
	//     return;
	//   }

	//   var data = JSON.parse(jsondata);
	//   for(var a in data){
	//      var user_rules=Object();
	//      user_rules['package_name']=data[a].package_name;
	//      user_rules['error_info']=data[a].info;
	//      user_rules['error_desc']=data[a].desc;
	//      jPut.users_ruels.append(user_rules);
	//   }
	// }

	$(function() {
		$(document)
			.on('click', '._request_param_del', function() {
				var that = $(this);
				that.parent().parent('._raw_request_param').remove();
			})

		.on('click', '._return_param_del', function() {
			var that = $(this);
			that.parent().parent('._raw_return_param').remove();
		})

		.on('click', '._error_param_del', function() {
			var that = $(this);
			that.parent().parent('._raw_error_param').remove();
		})
	});

	function getApiData() {
		var service_id = $('._service_id').val();
		var service_name_en = $('._service_name_en').val();
		var service_name = $('._service_name').val();
		var api_name = $('._api_name').val();
		var api_name_en = $('._api_name_en').val();
		var api_introduction = $('._api_introduction').val();
		//var api_timeout = $('._api_timeout').val();
		//请求方式
		var api_request_method = $("input[name='api_request_method']:checked").val()
		var api_result_format = $("._api_result_format").val();
		var api_authorized_type = $("._api_authorized_type").val();
		var api_uri = $('._api_uri').val();
		// var api_sample_url = $("._api_sample_url").val();

		var api_request_param = JSON.parse(getApiRequestParam("api_request_param", ['name', 'type', 'mast', 'default_value', 'desc'], 5));
		//console.log(api_request_param);//return;
		var param_str = getParam(api_request_param);
		var api_sample_url = "http://{$info.service_host}/" + api_uri + "?" + param_str;

		var api_result_field = JSON.parse(getApiRequestParam("api_result_field", ['name', 'type', 'desc'], 3));
		var result_field_str = getResultField(api_result_field);

		var api_error_codes = JSON.parse(getApiRequestParam("api_error_codes", ['code', 'info', 'desc'], 3));
		var api_result_sample = $("._api_result_sample").val();
		var api_other_platform_sample = $("._api_other_platform_sample").val();
		var api_update_type = $("input[name='api_update_type']:checked").val()
			// var api_is_charge = $('._api_is_charge').val();
		var api_is_charge = $("input[name='api_is_charge']:checked").val();

		//参数为空判断
		batchVer('_blur_rz');

		//有错误样式不允许提交
		if(haserror('_blur_rz')) {
			return false;
		}
		//请求参数判断
		if(param_str == 'no') {
			return false;
		}
		//请求参数判断
		if(result_field_str == 'no') {
			return false;
		}

		//api提交
		var data = {};
		data.service_id = service_id;
		data.api_id = $('._api_id').val();
		data.api_name = api_name;
		data.service_name_en = service_name_en;
		data.service_name = service_name;
		data.api_name_en = api_name_en;
		data.api_introduction = api_introduction;
		//data.api_timeout = api_timeout;
		data.api_request_method = api_request_method;
		data.api_result_format = api_result_format;
		data.api_authorized_type = api_authorized_type;
		data.api_uri = api_uri;
		data.api_sample_url = api_sample_url;
		data.api_request_param = api_request_param;
		data.api_result_field = api_result_field;
		data.api_error_codes = api_error_codes;
		data.api_result_sample = api_result_sample;
		data.api_other_platform_sample = api_other_platform_sample;
		data.api_update_type = api_update_type;
		data.api_is_charge = api_is_charge;

		return data;

	}

	//拼装请求样例
	function getParam(datajson) {

		var param_string = "";
		var rsv = true;
		for(var k in datajson) {
			if(!stringIsNull($.trim(datajson[k].name)) && !checkEnName(datajson[k].name)) {
				rsv = false;
			}
			param_string += "&" + datajson[k].name + "=" + datajson[k].default_value;
		}
		if(!rsv) {
			return 'no';
		}
		param_string = param_string.substr(1);
		param_string = param_string.replace(' ', '');
		return param_string;
	}

	function getResultField(datajson) {
		var rsv = true;
		for(var k in datajson) {
			if(!stringIsNull($.trim(datajson[k].name)) && !checkEnName(datajson[k].name)) {
				rsv = false;
				//return false;
			}
		}
		if(!rsv) {
			return 'no';
		}
		return 'yes';
	}

	//获取二维数组值及转json数据格式
	function getApiRequestParam(dom_name, params, params_num) {
		var api_request_param = $("input[name^='" + dom_name + "']");
		//console.log(api_request_param);
		var json_params = new Array();

		var array_num = Math.floor(api_request_param.length / params_num);
		for(var j = 0; j < array_num; j++) {
			//json_params[j] = new Array();
			json_params[j] = new Object();
		}

		for(var i = 0; i < api_request_param.length; i++) {
			var num = i % params_num;
			var key = Math.floor(i / params_num);
			json_params[key][params[num]] = api_request_param[i].value;
		}
		return JSON.stringify(json_params);
	}

	// 获取option值
	function selectChange(obj, classname, val) {
		var val = $(obj).val();
		$(obj).next('input[name=\'' + classname + '\']').val(val);
	}
</script>
<script src="__PUBLIC__/home/js/apiupdate.js"></script>
<script src="__PUBLIC__/home/js/waitMe.js"></script>
<script src="__PUBLIC__/home/js/apiadd-add.js"></script>

</html>